<template scope="scope">
	<div>
		<!--<table>
			<tr>
				<th>sda</th>
				<th>asfda</th>
				<th>asdfas</th>
			</tr>
			<tr v-for="">
				<td></td>
				<td></td>
				<td></td>
			</tr>
			
		</table>
		-->

		<div class="table">
			<el-table :data="tableData" style="text-align: center;">
				<el-table-column prop="noticeId" label="序号" width="180px">
				</el-table-column>
				<el-table-column prop="noticeName" label="公告名称" width="180px">
				</el-table-column>
				<el-table-column prop="noticeCreateDate" label="发布日期" width="300px" :formatter="dateFormat">
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">

						<el-button type="primary" @click="getDetail(scope.row)">查看</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<!--分页-->
		<div class="block">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import { noticeList, getNoticeById } from '@/axios/api'
	import { formatDate } from '@/axios/date.js'
	export default {
		data() {
			return {
				pageIndex: 1,
				pageSize: 10,
				total: 0,
				tableData: []
			}
		},
		methods: {
				/*日期格式化*/
				dateFormat(row, column) {
					var date = row[column.property];
					//console.log(date);
					return formatDate(new Date(date), 'yyyy-MM-dd');
				},
				/*dateFormat(row, column) {
					var date = row[column.property];
					//console.log(date);
					return moment(new Date(date)).format('YYYY-MM-DD HH:mm:ss');
				},*/
			
			/*filters: {
				formatDate(time) {
					var date = new Date(time);
					return '';
				}
			},*/

			/*分页*/
			handleSizeChange(val) {
				//console.log(`每页 ${val} 条`);
			},
			handleCurrentChange(val) {
				//this.pageIndex = val;
				let param = {
					pageIndex: val
				};
				console.log(param);
				noticeList(param).then(res => {
					this.tableData = res.resData.list,
						console.log(this.tableData),
						//console.log(this.res.tableData.total),
						this.total = res.resData.total
					//this.pageSize = res.resData.pageSize

				})
			},
			/*显示公告内容*/
			getDetail(notice) {
				let param = {
					id: notice.noticeId
				};
				getNoticeById(param).then(res => {
					this.noticeInf = res.resData.noticeInf,
						this.noticeName = res.resData.noticeName,
						//console.log(res.resData.noticeInf);
						this.$alert(this.noticeInf, this.noticeName, {
							confirmButtonText: '确定'
						});

				})

			},
			/*公告列表*/
			noticeList2() {
				let param = {
					pageIndex: this.pageIndex
				};
				noticeList(param).then(res => {
					this.tableData = res.resData.list,
						console.log(res.resData.list.noticeCreateDate),
						console.log(this.tableData.noticeCreateDate),
						this.total = res.resData.total
					//this.pageSize = res.resData.pageSize
					//this.tableData.noticeCreateDate=formatDate(new Date(res.resData.list.noticeCreateDate),"yyyy/MM/dd")

				})
			}
		},
		mounted() {
			this.noticeList2()
			//this.getDetails()
		}
	}
</script>
<style type="text/css">
	.table {
		margin: 50px;
	}
	.el-table th {
		text-align: center;
	}
</style>